package com.dingwei.superiordiary.mvp.presenter;

import com.dingwei.superiordiary.base.MyBaseBean;
import com.dingwei.superiordiary.bean.FailsBean;
import com.dingwei.superiordiary.bean.MyLikesBean;
import com.dingwei.superiordiary.bean.MyPostsBean;
import com.dingwei.superiordiary.custom.myCallback;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class MyLikesPresenter extends basePresenter {

    private Contract.MyLikesView myLikesView;

    public MyLikesPresenter(Contract.MyLikesView view) {
        super(view);
        this.myLikesView = view;
    }

    public void initData(int page, final boolean isRefresh, boolean isShowDialog) {
        RequestParams rp = new RequestParams(URLS.HOST + URLS.myFabulousList);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        rp.addBodyParameter("page", page + "");
        x.http().post(rp, new myCallback(BaseActivity.context, MyLikesBean.class, isShowDialog, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                MyLikesBean bean = (MyLikesBean) baseBean;
                if (isRefresh) {
                    myLikesView.onRefresh(bean);
                } else {
                    myLikesView.onLoadMore(bean);
                }
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
                myLikesView.onFail();
            }
        });
    }
}
